<template>
	<view class="" style="padding: 40rpx;">
		<view class="control box_radius">
			<u-toast ref="uToast" />
			<view class="system box box-pack-between box-align-center">
				<view class="system_left box box-align-center">
					<view class="system_img">
						<image src="https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/shujuxian.png" mode=""></image>
					</view>
					<view class="system_text">数据传输开关</view>
				</view>
				<view class="system_control">
					<u-switch v-model="settingForm.setting_usb" @change="((val)=>{dataChange(val, 'setting_usb')})" inactive-color="#e2e2e2"
						swtichTxt>
					</u-switch>
				</view>
			</view>
			<view class="system box box-pack-between box-align-center">
				<view class="system_left box box-align-center">
					<view class="system_img">
						<image src="https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/lanya.png" mode=""></image>
					</view>
					<view class="system_text">蓝牙总开关</view>
				</view>
				<view class="system_control">
					<u-switch v-model="settingForm.setting_bht" @change="((val)=>{dataChange(val, 'setting_bht')})" inactive-color="#e2e2e2" swtichTxt>
					</u-switch>
				</view>
			</view>
			<view class="system box box-pack-between box-align-center" v-if="settingForm.setting_bht">
				<view class="system_left box box-align-center">
					<view class="system_img">
						<image src="https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/lanya.png" mode=""></image>
					</view>
					<view class="system_text">蓝牙传输开关</view>
				</view>
				<view class="system_control">
					<u-switch v-model="settingForm.setting_bluetooth" @change="((val)=>{dataChange(val, 'setting_bluetooth')})" inactive-color="#e2e2e2" swtichTxt>
					</u-switch>
				</view>
			</view>
			<view class="system box box-pack-between box-align-center">
				<view class="system_left box box-align-center">
					<view class="system_img">
						<image src="https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/ka.png" mode=""></image>
					</view>
					<view class="system_text">储存卡传输开关</view>
				</view>
				<view class="system_control">
					<u-switch v-model="settingForm.setting_memory" @change="((val)=>{dataChange(val, 'setting_memory')})" inactive-color="#e2e2e2" swtichTxt></u-switch>
				</view>
			</view>
			<view class="system box box-pack-between box-align-center">
				<view class="system_left box box-align-center">
					<view class="system_img">
						<image src="https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/control1.png" mode=""></image>
					</view>
					<view class="system_text">恢复出厂设置开关</view>
				</view>
				<view class="system_control">
					<u-switch v-model="settingForm.qch_restore" @change="((val)=>{dataChange(val, 'qch_restore')})" inactive-color="#e2e2e2" swtichTxt>
					</u-switch>
				</view>
			</view>
			<view class="system box box-pack-between box-align-center">
				<view class="system_left box box-align-center">
					<view class="system_img">
						<image src="https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/control6.png" mode=""></image>
					</view>
					<view class="system_text">wifi共享热点开关</view>
				</view>
				<view class="system_control">
					<u-switch v-model="settingForm.setting_hotspot" @change="((val)=>{dataChange(val, 'setting_hotspot')})" inactive-color="#e2e2e2" swtichTxt>
					</u-switch>
				</view>
			</view>
			<view class="system box box-pack-between box-align-center">
				<view class="system_left box box-align-center">
					<view class="system_img">
						<image src="https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/control2.png" mode=""></image>
					</view>
					<view class="system_text">开发者模式选项开关</view>
				</view>
				<view class="system_control">
					<u-switch v-model="settingForm.is_developer" @change="changeDeveloper" inactive-color="#e2e2e2" swtichTxt></u-switch>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getSetting,
		editSetting,
		queryTypeTfMedia,
		editDeveloper
	} from '@/api/systemControl.js'
	export default {
		data() {
			return {
				userId: 0,
				id: 0,
				//图形文件格式黑名单
				graph: {
					checkAll: false,
					checkedCities: [],
					cities: [],
				},
				//音频文件格式黑名单
				voice: {
					checkAll: false,
					checkedCities: [],
					cities: [],
				},
				//视频文件格式黑名单
				videos: {
					checkAll: false,
					checkedCities: [],
					cities: []
				},
				//文档文件格式黑名单
				docum: {
					checkAll: false,
					checkedCities: [],
					cities: []
				},
				formatShow: false,
				settingForm: {
					setting_usb: false,
					setting_bluetooth: false,
					setting_bht: false,
					setting_memory: false,
					qch_restore: false,
					setting_hotspot: false,
					is_developer: false,
					setting_call: false,
				},
			}
		},
		beforeCreate() {
			this.userId = uni.getStorageSync('userId')
		},
		created() {
			
		},
		beforeMount() {
			this.getSettings(uni.getStorageSync('snId'))
		},
		methods: {
			//获取管控设备信息
			getSettings(id) {
				getSetting({
					id: id
				}).then(res => {
					let data = res.data
					this.settingForm.setting_usb = Boolean(data.setting_usb)
					this.settingForm.setting_bluetooth = Boolean(data.setting_bluetooth)
					this.settingForm.setting_memory = Boolean(data.setting_memory)
					this.settingForm.setting_call = Boolean(data.setting_call)
					this.settingForm.qch_restore = Boolean(data.qch_restore)
					this.settingForm.setting_hotspot = Boolean(data.setting_hotspot)
					this.settingForm.is_developer = Boolean(data.is_developer)
					this.settingForm.setting_bht = Boolean(data.setting_bht)
					this.id = data.id
				}).catch(err => {
					
				})
			},
			//修改系统管控信息
			dataChange(val, name) {
                let editForm = {
					userId: uni.getStorageSync('userId'),
					lastIp: uni.getStorageSync('Ip'),
					name: name,
					value: Number(val),
					snId: uni.getStorageSync('snId'),
					id: this.id
				}
				editSetting(editForm).then(res => {
					this.getSettings(uni.getStorageSync('snId'))
					this.$refs.uToast.show({
						title: res.msg,
						icon: false,
						type: 'success'
					})
				}).catch(err => {
					this.$refs.uToast.show({
						title: err.msg,
						icon: false,
						type: 'error'
					})
					this.getSettings(uni.getStorageSync('snId'))
				})
			},
			//编辑开发者模式
			changeDeveloper(val) {
				let data = {
					userId: uni.getStorageSync('userId'),
					lastIp: uni.getStorageSync('Ip'),
					isDeveloper: Number(val),
					id: uni.getStorageSync('snId')
				}
				editDeveloper(data).then(res => {
					this.getSettings(uni.getStorageSync('snId'))
					this.$refs.uToast.show({
						title: res.msg,
						icon: false,
						type: 'success'
					})
					
				}).catch(err => {
					this.$refs.uToast.show({
						title: err.msg,
						icon: false,
						type: 'error'
					})
					this.getSettings(uni.getStorageSync('snId'))
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #FFFFFF;
	}
</style>
<style lang="less" scoped>
	.control {
		background-color: #f2f1f1;
		padding: 0 40rpx;

		image {
			height: 100%;
			width: 100%;
		}

		.system_img {
			width: 80rpx;
			height: 80rpx;
		}

		.system_text {
			font-size: 28rpx;
			letter-spacing: 2rpx;
			margin-left: 40rpx;
		}

		.system {
			margin-top: 14.5px;
			border-bottom: 2rpx solid #e8e8e8;
			padding-bottom: 14.5px;
		}
	}
</style>
